package com.lry.basic.jvm.rpc;

import javax.naming.ldap.HasControls;
import java.lang.reflect.Method;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2019/12/23
 */
public class JavaClassExecuter {
    public static String execute(byte[]classByte){
        HackSystem.clearBuffer();
        ClassModifier cm = new ClassModifier(classByte);
        byte[] modifyBytes = cm.modifyUTF8Constant("java/lang/System","com/lry/basic/jvm/rpc/HackSystem");
        HotSwapClassLoader loader = new HotSwapClassLoader();
        Class clazz = loader.loadByte(modifyBytes);
        try {
            Method method = clazz.getDeclaredMethod("main",new Class[]{String[].class});
            method.invoke(clazz,new String[]{null});
//            method.invoke(null,new String[]{null});
        } catch (Exception e) {
            e.printStackTrace();
        }
        return HackSystem.getBufferString();
    }
}
